  const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const ROOT_URL = "https://zuimei.51appdevelop.com";
//  const ROOT_URL = "http://www.bwm.com";


//请求数据
const ajax = function (url, config, success, err) {
  let opt = {
    url: ROOT_URL + url,
    data: config.data || "",
    method: !config.method ? 'POST' : config.method.toUpperCase(),
    header: config.header || {},
    dataType: config.datatype || 'json',
    complete: function (res) {
      // console.log(res)
      if (res.statusCode >= '200' && res.statusCode <= '206' || res.statusCode == '304') {
        if (typeof success == "function") {
          success(res.data);
        }
      } else {
        console.log(res)
        if (typeof err == "function") {
          err(res);
        }
      }
    }
  }
  wx.request(opt)
}
const errorToast = function (title) {
  wx.hideToast();
  wx.showToast({
    title: title,
    icon: 'none'
  })
}
const empty = (str) => {
  if (str === "" || str == undefined || str == null) {
    return false;
  } else {
    return true;
  }
}
const isPhone = (str) => {
  let reg = /^1[3,5,7,8]\d{9}$/;
  return reg.test(str);
}

module.exports = {
  formatTime: formatTime,
  empty: empty,
  isPhone: isPhone,
  errorToast: errorToast,
  ajax: ajax,
  ROOT_URL
}
